package com.ruoyi.blog.controller;

import com.ruoyi.blog.core.controller.BaseController;
import com.ruoyi.blog.core.domain.AjaxResult;
import com.ruoyi.blog.core.page.TableDataInfo;
import com.ruoyi.blog.domain.BlogCategory;
import com.ruoyi.blog.domain.BlogTags;
import com.ruoyi.blog.service.BlogCategoryService;
import com.ruoyi.blog.service.BlogTagsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

import static com.ruoyi.blog.utils.DateUtils.getNowDate;

/**
 * @Author: 依梦
 * @Date: 2024/10/10
 * @Description: BlogTagsController
 */
@RestController
@RequestMapping("/blog/tags")
public class BlogTagsController extends BaseController {
    @Resource
    private BlogTagsService blogTagsService;


    @GetMapping("/list")
    public TableDataInfo getList(BlogTags blogTags) {
        startPage();
        List<BlogTags> list = blogTagsService.getList(blogTags);
        return getDataTable(list);
    }

    @GetMapping("/all")
    public AjaxResult getAll() {
        return AjaxResult.success(blogTagsService.getAll());
    }

    @PostMapping("/add")
    public AjaxResult add(@RequestBody BlogTags blogTags) {
        blogTags.setCreateBy(getUserId());
        blogTags.setCreateTime(getNowDate());
        blogTags.setUpdateBy(getUserId());
        blogTags.setUpdateTime(getNowDate());
        return toAjax(blogTagsService.save(blogTags));
    }

    @PutMapping("/update")
    public AjaxResult updateById(@RequestBody BlogTags blogTags) {
        return toAjax(blogTagsService.updateById(blogTags));
    }

    @DeleteMapping("/remove/{btId}")
    public AjaxResult removeById(@PathVariable(value = "btId") Long btId) {
        return toAjax(blogTagsService.removeById(btId));
    }
}
